﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace LoanMonitor
{
    public partial class FinanceTextbox : UserControl
    {
        public TextBox TextBox1
        {
            set { this.textBox1 = value; }
            get { return textBox1; }
        }
        public FinanceTextbox()
        {
            InitializeComponent();
        }
        private void Format_TextBox(object sender, EventArgs e)
        {
            string s = ((TextBox)sender).Text.Trim();
            char[] ch = s.ToCharArray();

            StringBuilder sb = new StringBuilder();

            foreach (char c in ch)
            {
                if (Char.IsDigit(c))
                {
                    sb.Append(c);
                }
            }

            if (sb.Length >= 1)
            {
                ((TextBox)sender).Text = Convert.ToDecimal(sb.ToString()).ToString("N0");
                ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length;
            }
            else
            {
                ((TextBox)sender).Clear();
            }
        }
    }
}
